#ifndef __GLOBAL_HEAD_H_
#define __GLOBAL_HEAD_H_
#define DEBUG_TEST 1
#include <stdio.h>
#include <strings.h>
#include <stdlib.h>
#include <pthread.h>
#define GOODS_MAX 10
#define G_KIND_MAX 10
#define G_NAME_MAX 20
#define STORAGE_NUM 10
#define QUEUE_MSG_LEN 1024
#define ID_MAX 32
#define NAME_MAX 32
#define PASSWORD_MAX 32

#define C_LOGIN 1
#define C_REGISTER 2
#define C_ENV   3
#define C_CMD  4
#define C_SMS  5
#define C_WIFI 6
#define C_GPS   7
#define S_LOGIN_ID_UNEXIST 10
#define S_LOGIN_PASSWORD_EXIST 11
#define S_LOGIN_OK 12
#define S_REGISTER_ID_EXIST 13
#define S_REGISTER_OK 14


typedef unsigned int uint;
typedef unsigned char uchar;

typedef enum bool{
	true = 1,
	false = 0
}bool;

//环境信息
struct env_info{
	int e_temperature;  //温度
	uint e_humlidity;   //湿度
	uint e_illumination;  //光照
	int e_x;   //三轴X   
	int e_y;    //三轴Y
	int e_z;	   //三轴Z
	char e_fan;   //风扇状态
	bool e_led[4]; //LED
	bool e_buzzer;    //蜂鸣器
	int e_battery;    //电池电量
	int e_adc ;       //电位器
};
//环境阈值
struct threshold_info{
	int t_temperature_max;
	int t_temperature_min;
	uint t_humlidity_max;
	uint t_humlidity_min;
	uint t_illumination_max;
	uint t_illumination_min;
	int t_x_max;
	int t_x_min;
	int t_y_max;
	int t_y_min;
	int t_z_max;
	int t_z_min;
	int t_battery_max;
	int t_battery_min;
	int t_adc_max;
	int t_adc_min;
};
//货物信息
struct goods_info{
	int g_id;  //货物编号
	char g_name[G_NAME_MAX]; //货物名称
	int g_num;   //货物数量
	char g_kind[G_KIND_MAX];  //货物类别
	int g_io;    //进出状态
};
//仓库信息
struct storage_info{
	int s_house_no; //所属仓库编号
	int storage_status;
	struct env_info s_env;
	struct threshold_info s_threshold;
	struct goods_info s_goods[GOODS_MAX];
};
//仓库管理大结构体
struct all_info{
	struct storage_info storage_dev[STORAGE_NUM];
};

struct msg_queue{
	long type;
	long msgtype; //具体消息类型
	char text[QUEUE_MSG_LEN];
};
struct user_info{
	char id[ID_MAX];
	char name[NAME_MAX];
	char password[PASSWORD_MAX];
	int limit;
};
struct mutex{
	pthread_mutex_t mutex_global; //大结构体锁
	pthread_mutex_t mutex_sqlite; //数据库锁
//	pthread_mutex_t mutex_linklist; //链表锁
	pthread_mutex_t mutex_link_data;
	pthread_mutex_t mutex_link_cmd;
	pthread_mutex_t mutex_link_db;
	pthread_mutex_t mutex_analysis; //数据处理锁
	pthread_mutex_t mutex_refresh; //数据刷新线程锁
	pthread_mutex_t mutex_zigbee_recv;//数据接收
	pthread_mutex_t mutex_zigbee_send;//数据发送
	pthread_mutex_t mutex_led;
	pthread_mutex_t mutex_camera;
	pthread_mutex_t mutex_buzzer;
#if DEBUG_TEST
	pthread_mutex_t mutex_input_test;
	pthread_mutex_t mutex_output_test;
#endif
};
struct cond{
	pthread_cond_t cond_sqlite;
	pthread_cond_t cond_request;
	pthread_cond_t cond_refresh;
	pthread_cond_t cond_led;
	pthread_cond_t cond_buzzer;
	pthread_cond_t cond_analysis;
	pthread_cond_t cond_zigbee_send;
#if DEBUG_TEST
	pthread_cond_t cond_input_test;
	pthread_cond_t cond_output_test;
#endif
};
struct pthread{
	pthread_t thread_refresh;
	pthread_t thread_sqlite;
	pthread_t thread_analysis;
	pthread_t thread_zigbee_recv;
	pthread_t thread_zigbee_send;
	pthread_t thread_led;
	pthread_t thread_camera;
	pthread_t thread_buzzer;
	pthread_t thread_request;
#if DEBUG_TEST
	pthread_t thread_input_test;
	pthread_t thread_output_test;
#endif
};
struct wifi{
	char gateway[12];
	char ip[12];
};
extern struct all_info all_storage_data;
extern struct mutex mutex;
extern struct cond cond;
extern struct pthread thread;
extern struct linkqueue *link_data;
extern struct linkqueue *link_cmd;
extern struct linkqueue *link_db;
#endif










